package leetcode;

import leetcode.tree.TreeNode;

/**
 * @author MaoLin Wang
 * @date 2020/10/9 2:20 下午
 */
public class _28对称的二叉树 {
    public static boolean isSymmetric(TreeNode root) {
        if (root==null){
            return true;
        }
        return same(root.left,root.right);
    }

    private static boolean same(TreeNode left, TreeNode right) {
        if (left==null && right == null ){
            return true;
        }
        if (left == null) {
            return false;
        }
        if (right==null){
            return false;
        }
        return left.val==right.val && same(left.left,right.right) && same(left.right,right.left);
    }
}
